package com.explment.lens.controller.user;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.explment.lens.entity.SysUserEntity;
import com.explment.lens.service.SysUserService;
import org.springframework.web.bind.annotation.*;
import org.springframework.beans.factory.annotation.Autowired;
import com.explment.lens.utils.result.ResultData;
/**
 * 系统用户 controller
 */
@RestController
@RequestMapping("/sysUserEntity")
public class SysUserController {
    @Autowired
    private SysUserService sysUserEntityService;

    @GetMapping("/{id}")
    public ResultData getById(@PathVariable("id") String id) {
        return ResultData.success(sysUserEntityService.getById(id));
    }

    /**
     * 分页查询
     * @param pageNum
     * @param pageSize
     * @return
     */
    @GetMapping("/page")
    public ResultData pageUsers(@PathVariable("pageNum")int pageNum, @PathVariable("pageSize")int pageSize,SysUserEntity sysUser) {
        Page<SysUserEntity> page = new Page<>(pageNum, pageSize);
        sysUserEntityService.page(page,null);
        return ResultData.success(page);
    }

    /**
     * 添加用户
     * @param sysUser
     * @return
     */
    @PostMapping("/insert")
    public ResultData create(@RequestBody SysUserEntity sysUser) {
        return ResultData.success(sysUserEntityService.save(sysUser));
    }


    @PutMapping("/{id}")
    public ResultData update(@RequestBody SysUserEntity sysUser) {
        return ResultData.success(sysUserEntityService.updateById(sysUser));
    }
}